package club.justwill.single.persistence.jpo;


import club.justwill.single.persistence.support.UserBase;

import javax.persistence.*;
import java.lang.reflect.Array;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by xiangnan on 10/28/15.
 */
@Entity
@Table(name = "users")
@NamedQueries({
        @NamedQuery(name="User.getById",
                query="select usr from User usr where usr.userId=:userId"),
        @NamedQuery(name="User.getByUserAliasName",
                query="select usr from User usr inner join usr.userAliasesSet alia where alia.aliasName =:aliasName"),
        @NamedQuery(name="User.getByInvitationCode",
                query="select usr from User usr where usr.invitationCode = :invitationCode"),
        @NamedQuery(name="User.getUsers",
                query="select usr from User usr")
})
public class User extends UserBase {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "user_id")
    private Long userId;

    //一个用户可以邀请多个用户 用户跟Invitation是一对多
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "inviter")
    @OrderBy("proc_ts desc")
    private Set<Invitation> inviteeSet;

    //一个用户也可以被多个用户邀请
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "invitee")
    @OrderBy("proc_ts desc")
    private Set<Invitation> inviterSet;

    //一个用户可以有多个别名 用户跟别名是一对多关系 一方
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    @OrderBy("proc_ts desc")
    private Set<UserAliases> userAliasesSet;

    //一个用户可以发布多个项目 用户跟项目是一对多关系 一方
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    @OrderBy("proc_ts desc")
    private Set<Projects> projectsSet;

    //一个用户可以有多种认证方式，用户跟认证是多对多关系
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    @OrderBy("proc_ts desc")
    private Set<Audit> auditSet;

    //一个用户可以签多个协议，用户跟协议是一对多关系 一方
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    @OrderBy("proc_ts desc")
    private Set<Agreement> agreementSet;

    //一个用户可以对应多个Userctivity 一对多 一方
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    @OrderBy("proc_ts desc")
    private Set<UserActivity> userActivitySet;

    //一个用户可以有多个订单 用户跟订单是一对多关系，一方
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    @OrderBy("proc_ts desc")
    private Set<Orders> ordersSet;

    //一个用户可以有多个账单，用户跟账单是一对多关系 一方
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    @OrderBy("proc_ts desc")
    private Set<Bill> billSet;


    public Set<Bill> getBillSet() {
        if(billSet == null) {
            billSet = new HashSet<Bill>();
        }
        return billSet;
    }

    public void setBillSet(Set<Bill> billSet) {
        this.billSet = billSet;
    }

    public Set<UserActivity> getUserActivitySet() {
        if(userActivitySet == null) {
            userActivitySet = new HashSet<UserActivity>();
        }
        return userActivitySet;
    }

    public void setUserActivitySet(Set<UserActivity> userActivitySet) {
        this.userActivitySet = userActivitySet;
    }

    public Set<Orders> getOrdersSet() {
        if(ordersSet == null) {
            ordersSet = new HashSet<Orders>();
        }
        return ordersSet;
    }

    public void setOrdersSet(Set<Orders> ordersSet) {
        this.ordersSet = ordersSet;
    }

    public Set<Audit> getAuditSet() {
        return auditSet;
    }

    public void setAuditSet(Set<Audit> auditSet) {
        this.auditSet = auditSet;
    }

    public Set<Agreement> getAgreementSet() {
        if(agreementSet == null) {
            agreementSet = new HashSet<Agreement>();
        }
        return agreementSet;
    }

    public void setAgreementSet(Set<Agreement> agreementSet) {
        this.agreementSet = agreementSet;
    }

    public Set<Projects> getProjectsSet() {
        if(projectsSet == null) {
            projectsSet = new HashSet<Projects>();
        }
        return projectsSet;
    }

    public void setProjectsSet(Set<Projects> projectsSet) {
        this.projectsSet = projectsSet;
    }

    public Set<UserAliases> getUserAliasesSet() {
        if(userAliasesSet == null) {
            userAliasesSet = new HashSet<UserAliases>();
        }
        return userAliasesSet;
    }

    public void setUserAliasesSet(Set<UserAliases> userAliasesSet) {
        this.userAliasesSet = userAliasesSet;
    }

    public Set<Invitation> getInviteeSet() {
        if(inviteeSet == null) {
            inviteeSet = new HashSet<Invitation>();
        }
        return inviteeSet;
    }

    public void setInviteeSet(Set<Invitation> inviteeSet) {
        this.inviteeSet = inviteeSet;
    }

    public Set<Invitation> getInviterSet() {
        if(inviterSet == null) {
            inviterSet = new HashSet<Invitation>();
        }
        return inviterSet;
    }

    public void setInviterSet(Set<Invitation> inviterSet) {
        this.inviterSet = inviterSet;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }
}
